<!DOCTYPE html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生报名系统</title>
    <link rel="shortcut icon" href="./img/favicon.ico">

    <link href="./css/bootstrap.min.css" rel="stylesheet">
    <link href="./css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="./css/animate.min.css" rel="stylesheet">
    <link href="./css/style.min.css" rel="stylesheet">
    <link href="./css/common.min.css" rel="stylesheet">


    <link rel="stylesheet" href="css/plugins/fontawesome/releases/css/all.css">
    <link rel="stylesheet" href="css/bootstrap-table.min.css">

</head>
<body class="gray-bg">
<div class="wrapper wrapper-content" style="padding-top: 30px;">
    <div class="container animated bounceInDown">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h2><b>活动展示</b>
                            <a data-toggle="modal" class="btn btn-primary" href="#modal-form2">已参加的活动</a>
                        </h2>
                        <div>
                            <table data-toggle="table" id="table" data-pagination="true">
                                <!--<thead>
                                <tr>
                                    <th data-field="id">活动编号</th>
                                    <th data-field="oid">社团编号</th>
                                    <th data-field="name">社团名</th>
                                    <th data-field="title">活动名</th>
                                    <th data-field="details">简介</th>
                                    <th data-field="button">操作</th>
                                </tr>
                                </thead>-->
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="modal-form2" class="modal fade" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-12">
                        <h3 class="m-t-none m-b">已参加的活动</h3>
                        <h4 id=""></h4>
                        <table data-toggle="table" id="table2" data-pagination="true">
                            <thead>
                            <tr>
                                <th data-field="id">活动编号</th>
                                <th data-field="oid">社团编号</th>
                                <th data-field="tips">社团名</th>
                                <th data-field="logname">活动名</th>
                            </tr>
                            </thead>
                        </table>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-primary" data-dismiss="modal">
                                确定
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="./js/jquery.min.js" type="text/javascript"></script>
<script src="./js/plugins/ajax/popper.min.js" type="text/javascript"></script>
<script src="./js/bootstrap.min.js" type="text/javascript"></script>
<script src="./js/plugins/bootstrap/bootstrap-table.min.js" type="text/javascript"></script>
<script src="./js/plugins/bootstrap/bootstrap-table-zh-CN.js" type="text/javascript"></script>
<script src="./js/common.js"></script>

<script type="text/javascript">


    $(function () {
        var stuId;
        $.ajax({
            type: "GET",
            url: "http://localhost:8080/api/system/currentUser",
            dataType: "json",
            success: function (data) {
                stuId = data.user;
                $('h4').html("学号："+stuId)
                $.ajax({
                    type: "GET",
                    url: "http://localhost:8080/api/organ/affair/getOrganAffairListByUid?uid=" + stuId,
                    dataType: "json",
                    success: function (msg) {
                        $("#table2").bootstrapTable('load', msg.data);
                    },
                    error: function () {
                        //alert("错误");
                    }
                })
            }
        })
    })

    /*$(function () {
        $.ajax({
            type: "GET",
            url: "http://localhost:8080/api/organ/activity/getOrganActivityList?current=1&size=10",
            dataType: "json",
            success: function (msg) {
                $("#table").bootstrapTable('load', msg.data)
                /!*for (var i = 0; i < msg.data.length; i++) {
                    var option = document.createElement("option");
                    /!*$(option).val("[" + msg.data[i].id + "]" + msg.data[i].name);
                    $(option).text("[" + msg.data[i].id + "]" + msg.data[i].name);*!/
                    $(option).val(msg.data[i].id);
                    $(option).text(msg.data[i].id);
                    $('#oid').append(option);
                }*!/
            },
            error: function () {
                //alert("错误");
            }
        });
    });*/

    var stuId
    $(function () {
        $.ajax({
            type: "GET",
            url: "http://localhost:8080/api/system/currentUser",
            // url: "https://www.fastmock.site/mock/f50b06873b252f82df8edabf4bd868a4/demo/student",
            dataType: "json",
            success: function (data) {
                stuId = data.user;
            }
        })
    })

    $("#table").bootstrapTable({
        //只能看进行中的活动
        url: "http://localhost:8080/api/organ/activity/getOrganActivityListActive",
        data_local: "zh-US",//表格汉化
        pagination: true,
        pageNumber: "1",
        pageSize: "10",
        uniqueId: "id",
        striped: true, //是否显示行间隔色
        sidePagination: 'client', // client：前端分页
        pageList: [10, 20], //可选择单页记录数
        search: true,
        showRefresh: true,
        showToggle: true,
        showColumns: true,
        iconsPrefix: 'fa',
        icons: {
            refresh: "fa-sync",
            toggleOff: "fa-toggle-off",
            toggleOn: "fa-toggle-on",
            columns: "fa-th-list",
        },
        responseHandler: function (msg) {
            return msg.data;
        },
        columns: [{
            field: 'id',
            title: '活动编号',
            align: 'center'
        }, {
            field: 'oid',
            title: '社团编号',
            align: 'center'
        }, {
            field: 'name',
            title: '社团名',
            align: 'center'
        }, {
            field: 'title',
            title: '活动名',
            align: 'center'
        }, {
            field: 'details',
            title: '简介',
            align: 'center'
        }, {
            field: 'button',
            title: '操作',
            align: 'center',
            formatter: AddFunctionAlty,
            events: window.operateEvents = {
                'click #joinAct': function (e, value, row, index) {
                    $.ajax({
                        url: "http://localhost:8080/api/organ/affair/insertOrganAffair",
                        type: "POST",
                        data: JSON.stringify({
                            'oid': row.oid,
                            'uid': stuId,
                            'status': "1",
                            'priority': "1",
                            'logname': row.title,
                            'tips': row.name
                        }),
                        contentType: "application/json",
                        dataType: "json",
                        success: function (data) {
                            if (data == 0) {
                                console.log(JSON.stringify({
                                    'oid': row.oid,
                                    'uid': stuId,
                                    'status': "1",
                                    'priority': "1",
                                    'logname': row.title,
                                    'tips': row.name
                                }));
                                alert("成功参加！")
                            } else {
                                alert(data.msg);
                            }

                        }, error: function (XMLHttpRequest) {
                            console.log("错误状态：" + XMLHttpRequest.status);
                        }
                    })
                }
            }
        }]
    })

    function AddFunctionAlty(value, row, index) {
        return [
            '<button id = "joinAct" type = "button">参加</button>'
        ].join("")
    }

    /*$(function () {
        $.ajax({
            type: "GET",
            url: "https://www.fastmock.site/mock/f50b06873b252f82df8edabf4bd868a4/demo/student",
            dataType: "json",
            success: function (data) {
                $("#id").val(data.id);
            }
        })
    });*/

    /*$(function () {
        $.ajax({
            type: "GET",
            url: "http://localhost:8080/api/student/queryStudentListById/201641413417",
            dataType: "json",
            success: function (data) {
                $("#id").val(data.id);
            }
        })
    });*/


    /*$.fn.serializeObject = function () {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function () {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        })
        return o;
    }*/

    /*function join() {
        if ($("#oid").val() == "--请选择--") {
            alert("请选择社团编号！！")
        } else {
            $.ajax({
                // url: "/student2/shetuan",  // 接口地址
                url: "http://localhost:8080/api/organ/affair/insertOrganAffair",
                // url: "http://localhost:8080/api/organ/user/insertOrganUser",
                type: "POST",
                // data: JSON.stringify($("#joinForm").serializeObject()),//将表单序列化成一个对象，这里多个表单相加
                data: JSON.stringify($.extend({}, $("#joinForm").serializeObject(), {'status': "1", 'priority': "1"})),
                //serializeObject()引入上述函数，将表单序列化成一个对象
                //JSON.stringify()将对象转成字符串
                contentType: "application/json",
                datatype: "json",
                success: function (data) {
                    // swal(data.message);
                    // location.href="scm_po_fhqd.html";
                    console.log(JSON.stringify($.extend({}, $("#joinForm").serializeObject(), {
                        'status': 1,
                        'priority': 1
                    })));
                }, error: function (XMLHttpRequest) {
                    console.log("错误状态：" + XMLHttpRequest.status);
                }
            })
            alert("加入社团成功")
            // window.location.reload()
        }
    }*/
</script>

</body>
</html>